//读取子节点(固定方法)
function loadTreeChildNodes(ulId,parentId){
	var html = '';
	Jes.query('fmenu_pid_query_sql@bs',{param:{pId:parentId}},function(da){
		for(var i=0;i<da.length;i++){
			html += '<li><a href="javascript:void(0);" id="'+da[i].id+'" onclick="Jes.Topic.listInit(\''+da[i].id+'\',\''+da[i].name+'\');">'+da[i].name+'</a><ul><li parentId="'+da[i].id+'" class="loading.gif"><a href="javascript:void(0);">Loading</a></li></ul></li>';
		}
		Jes.html(ulId,html);
		if(html == ''){
			Jes.tag('IMG',Jes(ulId).parentNode)[0].style.visibility = "hidden";
			Jes.hide(ulId);
		}
		parseSubItems(ulId,parentId);
	});
}

//topic
Jes.Topic = {
	init : function(){
		if(!Jes.userSess()) return;
		initTabs('tabView_1',Array('信息管理'),0,"100%",90,Array(false));
		if(userInfo.account!='admin') Jes.hide('del');
		this.treeQuery();
		this.listInit('0','栏目架构树');
	}
	,myInit : function(){
		if(!Jes.userSess()) return;
		Jes.cBtn('../../jesacl/html/welcome.html');
		initTabs('tabView_1',Array('我的文章'),0,"100%",90,Array(false));
		this.myQuery();
		Jes.Menu.show();//栏目
	}
	,myQuery : function(){
		Jes.page('mytopic_query_sql@bs',{pageSize:10});
	}
	,treeQuery : function(){
		Jes.action('getFmenuTree@App',{},function(da){
			Jes.html('fmenu_tree',da);
			treeObj = new JSDragDropTree();
			treeObj.fn='Jes.Topic.listInit';
			treeObj.setTreeId('dhtml_tree');
			treeObj.setMaximumDepth(10);
			treeObj.setMessageMaximumDepthReached('超过最多级别'); // If you want to show a message when maximum depth is reached, i.e. on drop.
			treeObj.initTree();
			treeObj.expand(true);
			//treeObj.expandAll();
		});
	}
	,listInit : function(id,name){
		delTab('信息新增');
		delTab('信息编辑');
		Jes.show('div_detail');
		Jes.html('div_detail',Jes.html('div_list'));
		if(id==0){
			//Jes.html('div_detail','<h3>'+name+'</h3>');
			Jes.val('fmenuid','');
			Jes.html('info_title','所有栏目');
		}else{
			Jes.html('info_title',name);
			Jes.val('fmenuid',id);//论坛栏目ID
		}
		this.query();
	}
	,query : function(){
		DWRUtil.useLoadingMessage('正在读取数据...');
		Jes.page('topic_fmid_query_sql@bs',{pageSize:10,isLoad:false});
	}
	,del : function(){
		var ids = Jes.val('id');
		if(Jes.isNull(ids)){alert('至少选择一项!');return;}
		if(!confirm('你确定删除信息吗？')) return;
		Jes.sql({ids:ids,sql:'topic_delete_hql@bs'});
	}
	,open : function(type,id){
		var args= arguments;
		switch(type){
			case 'op':
					var fmenuid =Jes.val('fmenuid');
					//top.Jes.Dialog.open(id?'信息编辑':'信息新增','../../jesbase/html/topicop.html'.J({id:id,fmenuid:fmenuid}),850,550);
					_newTab(id?'信息编辑':'信息新增',"topicop.html".J({id:id,fmenuid:fmenuid}),true,600);
				break;
		}
	}

}

//op
Jes.TopicOp = {
	init : function(){
		DWRUtil.useLoadingMessage('正在读取数据...');
		if(!Jes.userSess()) return;
		Jes.Upload.clear();
		var req = Jes.request();
		Jes('add').onclick=function(){Jes.TopicOp.save();}//save
		Jes.cBtn();
		Jes.sync(function(){
			Jes.Select.css('cssid');
		});
		if(Jes.isNull(req.id)){//新增
			jscolor.init();
			Jes.TopicOp.showMenu(req.fmenuid);
			//username:userInfo.username,
			Jes.vals({deptname:'本站',posttime:Jes.curDate()
			,'modifyuserid':userInfo.userid,'modifyusername':userInfo.username,'fmenuid':req.fmenuid});
			Jes.fck('content','700','350');//,"Basic"
		}else{
			Jes.query('topic_id_query_sql@bs',{param:{id:req.id}},function(da){
				Jes.vals(da[0]);
				jscolor.init();
				Jes.Upload.showImg('ta_query1_img',da[0].img,260,190);
				var fmenuid ='';
				Jes.each(da,function(i){
					fmenuid += ((i==0)?'':',')+da[i].fmenuid;
				});
				Jes.TopicOp.showMenu(fmenuid);
				Jes.fck('content','720','350');//,"Basic"
			});
		}
		Jes.Upload.query({param:{bussid:req.id,busstype:'1'}});
		initTabs('tabView_1',Array('信息管理','附件信息'),0,"100%",90,Array(false,false));
	}
	,showMenu : function(fmenuid){
		Jes.show('addfmenu');
		Jes.action('getFmenuTree@App',{type:'checkbox',fmenuid:fmenuid,disabled:'0',pro:' title="栏目" rule="group"'},function(da){
			Jes.html('fmenu_tree',da);
			treeObj = new JSDragDropTree();
			//treeObj.setImageFolder('../../components/drag-drop-folder-tree/images/');//设置图片路径
			treeObj.setTreeId('dhtml_tree');
			treeObj.setMaximumDepth(10);
			//treeObj.setUserFunctionAfterDropDragableNodes(function(id,pId){changeParent(id,pId)});
			treeObj.setMessageMaximumDepthReached('超过最多级别'); // If you want to show a message when maximum depth is reached, i.e. on drop.
			treeObj.initTree();
			treeObj.expandAll();
			Jes.TopicOp.showMenuName();
		});
	}
	,showMenuName : function(){
		//默认
		Jes.hide('addimg','isdue','isvideo');
		Jes.show('iscontent');
		Jes.attr('content','notnull','');
		Jes('img').removeAttribute('notnull');
		//显示栏目名称
		var cks= Jes.name('tree.fmenuid'),el,name='';
		Jes.each(cks,function(i){
			el = cks[i];
			if(el.checked){
				if(el.istimg==1){//如果有图片新闻栏目
					Jes.show('addimg');
					Jes.attr('img','notnull','');
				}
				if(el.istdue==1) Jes.show('isdue');
				if(el.istvideo=='1'){//如果有视频栏目
					Jes.show('isvideo');
					Jes.hide('iscontent');
					Jes('content').removeAttribute('notnull');
				}
				name+=(name==''?'':' ')+'<span style="background-color:#8ce3be;padding:5px;color:#fff">'+el.nodename+'</span>';
			}
		});
		Jes.val('menu',name);
	}
	,editImg : function(){
		//ag
		Jes.FlyDiv.show("fdiv",null,null);
	}
	,editMenu : function(){
		Jes.FlyDiv.show("mdiv",null,null);
	}
	,selMenu : function(){
		Jes.TopicOp.showMenuName();
		Jes.FlyDiv.hide();
	}
	/*
	,color : function(obj){
		var title = Jes.val('title').delHtml();
		Jes.val('subject','<font color="#'+obj.value+'">'+subject+'</font>');
	}
	*/
	,save : function(){
		if(Jes('ta_query1_img.upname')) Jes.val('img',Jes('ta_query1_img.upname').value);
		else Jes.val('img','');
		Jes.save("TJesTopic");
	}
	,callVideo : function(da){
		Jes.val('vurl',da.httppath+'video/'+da.name);
	}
	,callImg : function(da){
		var fck = FCKeditorAPI.GetInstance('content');
		fck.InsertHtml('<img width="600" height="450" src="'+da.httppath+'img/'+da.name+'" />');
	}
}
